<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="采购方总部编码" prop="purchaserHqCode">
                <el-input v-model="queryParams.purchaserHqCode" placeholder="请输入采购方总部编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          <!--<el-form-item label="供应商编码" prop="supplierCode">
              <el-input v-model="queryParams.supplierCode" placeholder="请输入供应商编码"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="供应商名称" prop="supplierName">
              <el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="采购订单行项目 id" prop="poItemId">
              <el-input v-model="queryParams.poItemId" placeholder="请输入采购订单行项目 id"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>-->
            <el-form-item label="排产计划编码" prop="scheduleCode">
                <el-input v-model="queryParams.scheduleCode" placeholder="请输入排产计划编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
          <!--<el-form-item label="省公司单位编码" prop="provCoCode">
              <el-input v-model="queryParams.provCoCode" placeholder="请输入省公司单位编码"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="省公司单位名称" prop="provCoName">
              <el-input v-model="queryParams.provCoName" placeholder="请输入省公司单位名称"
                      clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
        <el-form-item label="计划工期" prop="planPeriod">
            <el-input v-model="queryParams.planPeriod" placeholder="请输入计划工期"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="实际工期" prop="actualPeriod">
            <el-input v-model="queryParams.actualPeriod" placeholder="请输入实际工期"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="进度" prop="schedule">
            <el-input v-model="queryParams.schedule" placeholder="请输入进度"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
                    <el-form-item label="交付日期" prop="dueDate">
                        <el-date-picker clearable v-model="queryParams.dueDate"
                                        type="date" value-format="yyyy-MM-dd" placeholder="请选择交付日期">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="计划开始日期" prop="planStartDate">
                        <el-date-picker clearable v-model="queryParams.planStartDate"
                                        type="date" value-format="yyyy-MM-dd" placeholder="请选择计划开始日期">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="计划完成日期" prop="planFinishDate">
                        <el-date-picker clearable v-model="queryParams.planFinishDate"
                                        type="date" value-format="yyyy-MM-dd" placeholder="请选择计划完成日期">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="实际开始日期" prop="actualStartDate">
                        <el-date-picker clearable v-model="queryParams.actualStartDate"
                                        type="date" value-format="yyyy-MM-dd" placeholder="请选择实际开始日期">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="实际完成日期" prop="actualFinishDate">
                        <el-date-picker clearable v-model="queryParams.actualFinishDate"
                                        type="date" value-format="yyyy-MM-dd" placeholder="请选择实际完成日期">
                        </el-date-picker>
                    </el-form-item>-->
            <el-form-item label="品类编码" prop="categoryCode">
                <el-input v-model="queryParams.categoryCode" placeholder="请输入品类编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="种类编码" prop="subclassCode">
                <el-input v-model="queryParams.subclassCode" placeholder="请输入种类编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                           v-hasPermi="['develop:FactoryProducePlan:add']">新增</el-button>
            </el-form-item>
        </el-form>

       <!-- <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['develop:FactoryProducePlan:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                        @click="handleUpdate" v-hasPermi="['develop:FactoryProducePlan:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                    <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                               v-hasPermi="['develop:FactoryProducePlan:remove']">删除</el-button>
                </el-popconfirm>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini"
                        @click="handleExport" v-hasPermi="['develop:FactoryProducePlan:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>-->

        <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight">
            <el-table-column type="selection" width="55" align="center"/>
                  <!--<el-table-column label="主键" align="center" prop="id"/>
                  <el-table-column label="状态" align="center" prop="status"/>-->
                  <el-table-column label="采购方总部编码" align="center" prop="purchaserHqCode"/>
                  <!--<el-table-column label="供应商编码" align="center" prop="supplierCode"/>
                  <el-table-column label="供应商名称" align="center" prop="supplierName"/>
                  <el-table-column label="采购订单行项目 id" align="center" prop="poItemId"/>-->
                  <el-table-column label="排产计划编码" align="center" prop="scheduleCode"/>
                  <!--<el-table-column label="省公司单位编码" align="center" prop="provCoCode"/>
                  <el-table-column label="省公司单位名称" align="center" prop="provCoName"/>-->
                  <el-table-column label="计划工期" align="center" prop="planPeriod"/>
                  <el-table-column label="实际工期" align="center" prop="actualPeriod"/>
                  <el-table-column label="进度" align="center" prop="schedule"/>
                  <el-table-column label="交付日期" align="center" prop="dueDate" width="180">
                      <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.dueDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                      </template>
                  </el-table-column>
                  <el-table-column label="计划开始日期" align="center" prop="planStartDate" width="180">
                      <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.planStartDate, '{y}-{m}-{d}') }}</span>
                      </template>
                  </el-table-column>
                  <el-table-column label="计划完成日期" align="center" prop="planFinishDate" width="180">
                      <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.planFinishDate, '{y}-{m}-{d}') }}</span>
                      </template>
                  </el-table-column>
                  <el-table-column label="实际开始日期" align="center" prop="actualStartDate" width="180">
                      <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.actualStartDate, '{y}-{m}-{d}') }}</span>
                      </template>
                  </el-table-column>
                  <el-table-column label="实际完成日期" align="center" prop="actualFinishDate" width="180">
                      <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.actualFinishDate, '{y}-{m}-{d}') }}</span>
                      </template>
                  </el-table-column>
                  <!--<el-table-column label="品类编码" align="center" prop="categoryCode"/>
                  <el-table-column label="种类编码" align="center" prop="subclassCode"/>-->
                  <el-table-column label="备注" align="center" prop="remark"/>
                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                      <template slot-scope="scope">
                          <el-button size="mini" type="text" icon="el-icon-edit"
                                  @click="handleUpdate(scope.row)" v-hasPermi="['develop:FactoryProducePlan:edit']">修改</el-button>
                          <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                         style="margin-left: 10px;">
                              <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                         v-hasPermi="['develop:FactoryProducePlan:remove']">删除</el-button>
                          </el-popconfirm>
                      </template>
                  </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

        <factoryProducePlan-form ref="form" @ok="getList"></factoryProducePlan-form>
    </div>
</template>

<script>
    import { deleteAction, getAction } from '@/api/manage'
    import FactoryProducePlanForm from '@/views/develop/factory/factoryProducePlan/module/FactoryProducePlanForm'

    export default {
        name: "FactoryProducePlanList",
        components: {
            FactoryProducePlanForm,
        },
        data() {
            return {
                title:'',
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 生产计划表格数据
                dataList: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    status: null,
                    purchaserHqCode: null,
                    supplierCode: null,
                    supplierName: null,
                    poItemId: null,
                    scheduleCode: null,
                    provCoCode: null,
                    provCoName: null,
                    planPeriod: null,
                    actualPeriod: null,
                    schedule: null,
                    dueDate: null,
                    planStartDate: null,
                    planFinishDate: null,
                    actualStartDate: null,
                    actualFinishDate: null,
                    categoryCode: "60",
                    subclassCode: "60004",
                    dataSource: null,
                    dataSourceCreateTime: null,
                    ownerId: null,
                    openId: null
                },
                url: {
                    list:'/factoryProducePlan/factoryProducePlan/list',
                    remove:'/factoryProducePlan/factoryProducePlan/',
                    export:'/factoryProducePlan/factoryProducePlan/export',
                },
                tableMaxHeight: window.innerHeight - 320,
            };
        },
        created() {
            this.getList();
            window.addEventListener('resize', this.getTableHeight);
        },
        destroyed () {
            window.removeEventListener('resize', this.getTableHeight)
        },
        methods: {
            /** 查询生产计划列表 */
            getList() {
                this.loading = true;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getTableHeight () {
                this.tableHeight = window.innerHeight - 320
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.remove, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
                this.download(this.url.export, {
                    ...this.queryParams
                }, `factoryProducePlan_${new Date().getTime()}.xlsx`)
            },
  }
};
</script>
